package com.example.kafka.controller;

import com.example.kafka.config.KafkaConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.annotation.KafkaListener;

/**
 * Kafka消费者
 * @author wanghongyu02
 * @date 2024-07-01 16:15
 */
@Configuration
@Slf4j
public class ConsumeController {

    @Autowired
    KafkaConfig kafkaConfig;

    /**
     * 使用KafkaListener的消费者
     * @author wanghongyu02
     * @date 2024-07-15 19:53
     * @param msg
     * @return
     */
//    @KafkaListener(topics = "mytopic1",idIsGroup = false,id = "1")
    public void consumeTopic(String msg) { // 参数: 收到的value
        log.info("消费者-收到的信息:{}",msg);
    }

    /**
     * 使用消费者工厂
     * @author wanghongyu02
     * @date 2024-07-15 19:53
     * @param msg
     * @return
     */
//    @KafkaListener(
//            topics = "mytopic1",
//            containerFactory = "kafkaListenerContainerFactory"
//    )
    public void consumeTopicByFactory(String msg) {
        log.info("消费者-收到的信息:{}",msg);
    }

}